# calculator.py
def add(a, b):
    return a + b

def subtract(a, b):
    return a - b

def multiply(a, b):
    return a * b

def divide(a, b):
    if b == 0:
        raise ValueError("除数不能为零")
    return a / b

if __name__ == "__main__":
    print("简单计算器")
    print("操作选项：+（加）、-（减）、*（乘）、/（除）")
    
    try:
        num1 = float(input("请输入第一个数字："))
        operator = input("请输入运算符：")
        num2 = float(input("请输入第二个数字："))
        
        if operator == '+':
            result = add(num1, num2)
        elif operator == '-':
            result = subtract(num1, num2)
        elif operator == '*':
            result = multiply(num1, num2)
        elif operator == '/':
            result = divide(num1, num2)
        else:
            print("无效的运算符")
            exit(1)
        
        print(f"计算结果：{num1} {operator} {num2} = {result}")
    
    except ValueError as e:
        print(f"错误：{e}")
    except Exception as e:
        print(f"发生异常：{e}")